#include "lib/includes.h"
#include "myother.h"

void SysDebug_TxDataStr( U08 *disbuf )	
{
	Hook_Debug_TxData((char*)disbuf);
}
void SysDebug_get_sys( U08 *inbuf, U32 insize )
{
	U32 rcode,i;
	U08 buf[120];
	U08 b1,b2,b3,b4;
	
	//============================>>用户文件1 系统参数
 	rcode = APP_Open_UseFile( DEF_USERID_SysCfg, sizeof( __SysCfg ) );
	if( rcode != 0 )
	{ goto Err1; }
	rcode = APP_Read_UseFile( DEF_USERID_SysCfg, (U08*)&SysCfg, sizeof( __SysCfg ) );
	if( rcode != 0 )
	{ goto Err1; }
	
	SysDebug_TxDataStr( (U08*)"=======>01 参数" );
	sprintf( (char*)buf, "版本:%u", SysCfg.Ver );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "时间:%02X%02X-%02X-%02X %02X:%02X:%02X", SysCfg.Time[0],SysCfg.Time[1],SysCfg.Time[2],SysCfg.Time[3],SysCfg.Time[4],SysCfg.Time[5],SysCfg.Time[6] );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "通讯类型:%u", SysCfg.ComType );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "Zigbee:%u", SysCfg.ZigbeeChannel );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "IP1:%u.%u.%u.%u %u", SysCfg.NetIPAddr01[0],SysCfg.NetIPAddr01[1],SysCfg.NetIPAddr01[2],SysCfg.NetIPAddr01[3],SysCfg.NetIPProt01 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "IP2:%u.%u.%u.%u %u", SysCfg.NetIPAddr02[0],SysCfg.NetIPAddr02[1],SysCfg.NetIPAddr02[2],SysCfg.NetIPAddr02[3],SysCfg.NetIPProt02 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "IP3:%u.%u.%u.%u %u", SysCfg.NetIPAddr03[0],SysCfg.NetIPAddr03[1],SysCfg.NetIPAddr03[2],SysCfg.NetIPAddr03[3],SysCfg.NetIPProt03 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "IP4:%u.%u.%u.%u %u", SysCfg.NetIPAddr04[0],SysCfg.NetIPAddr04[1],SysCfg.NetIPAddr04[2],SysCfg.NetIPAddr04[3],SysCfg.NetIPProt04 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "APN1:%s N:%s P:%s", SysCfg.NetAPN01, SysCfg.NetName01, SysCfg.NetPasd01 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "APN2:%s N:%s P:%s", SysCfg.NetAPN02, SysCfg.NetName02, SysCfg.NetPasd02 );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "定时连接时间:%u分钟", SysCfg.NetTimeCont);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "定量连接时间:%u条", SysCfg.NetCoutCont);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "连接超时时间:%uS", SysCfg.NetContTimeOut);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "通讯超时时间:%uS", SysCfg.NetTxRxTimeOut);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "COM超时时间:%uS", SysCfg.NetUARTTimeOut);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "复合卡选择:%u", SysCfg.CardUnSel);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "AB卡选择:%u", SysCfg.CardABSel);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "SAK值:%02X %02X", SysCfg.CardUnSak[0], SysCfg.CardUnSak[1]);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "Apps:%u", SysCfg.CardApps);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "Bpps:%u", SysCfg.CardBpps);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "7816pps:%u", SysCfg.Card7816pps);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "RF配置:%u %02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X", SysCfg.CardRFcfgSta,SysCfg.CardRFcfg[0],SysCfg.CardRFcfg[1],SysCfg.CardRFcfg[2],SysCfg.CardRFcfg[3],SysCfg.CardRFcfg[4],SysCfg.CardRFcfg[5],SysCfg.CardRFcfg[6],SysCfg.CardRFcfg[7]);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "业务选择:%u", SysCfg.AppBusSel);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "业务优先级:%u", SysCfg.AppBusPrior);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "银联记录上传:%u", SysCfg.AppBusRec);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "交易异常处理:%u", SysCfg.AppBusErrPro);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "卡内余额预警值:%u", SysCfg.AppBusMinBalanc);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "语言选择:%u", SysCfg.AppDisSel);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "显示屏选择:%u", SysCfg.AppDisLCD);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "进制:%u", SysCfg.AppHexDis);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "本地城市代码:%02X%02X", SysCfg.AppCityID[0],SysCfg.AppCityID[1]);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "语音播放状态:%u", SysCfg.AudioStat);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "语音音量:%u", SysCfg.AudioVolume);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "脉冲音状态:%u", SysCfg.AudioPwmStat);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "脉冲音频率:%u", SysCfg.AudioPwmf);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "脉冲时间:%u", SysCfg.AudioPwmTim);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "车辆编号:%u", SysCfg.CarCode);
	SysDebug_TxDataStr( buf );
	
	sprintf( (char*)buf, "TPDU:%02X%02X%02X%02X%02X", 
				UP_SysCfg.Tpdu[0],UP_SysCfg.Tpdu[1],UP_SysCfg.Tpdu[2],UP_SysCfg.Tpdu[3],UP_SysCfg.Tpdu[4]);
	SysDebug_TxDataStr( buf );
	
//============================>>用户文件2 线路票价
 	Err1:
	rcode = APP_Open_UseFile( DEF_USERID_DealCfg, sizeof( __DealCfg ) );
	if( rcode != 0 )
	{ goto Err2; }
	rcode = APP_Read_UseFile( DEF_USERID_DealCfg, (U08*)&DealCfg, sizeof( __DealCfg ) );
	if( rcode != 0 )
	{ goto Err2; }
	
	SysDebug_TxDataStr( (U08*)"=======>02 票价" );
	sprintf( (char*)buf, "版本:%u", DealCfg.Ver );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "时间:%02X%02X-%02X-%02X %02X:%02X:%02X", DealCfg.Time[0],DealCfg.Time[1],DealCfg.Time[2],DealCfg.Time[3],DealCfg.Time[4],DealCfg.Time[5],DealCfg.Time[6] );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "分公司标识:%u", DealCfg.FilialeID );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "线路标识:%02X%02X", DealCfg.CircuitryID[0], DealCfg.CircuitryID[1]);
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "普通票价:%u", DealCfg.UnitPrice );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "逃票票价:%u", DealCfg.FaultUnitPrice );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "票价数量:%u", DealCfg.CardTypeCout );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "分段收费状态:%u", DealCfg.TimePriceStat );
	SysDebug_TxDataStr( buf );
	//0:默认:不支持分段收费
										//1:按站收费设置每坐一站的收费情况，收费金额乘以坐的站点个数
										//2:按段收费设置坐不同距离的收费情况，如坐小于3站收费1元，大于3站小于5站收费2元
										//3:站站收费设置线路上不同站点之间的收费情况
										//4:里程收费里程*单价
										//5:里程区间
	
	
	sprintf( (char*)buf, "GPS状态:%u", DealCfg.GPSStat );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "GPS通讯时间:%uS", DealCfg.GPSContTime );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "GPS长短连接状态:%u", DealCfg.GPSLinkStat );
	SysDebug_TxDataStr( buf );
	b1 = (DealCfg.BusyPrice[0].StaHHMM>>8)&0xFF;
	b2 = DealCfg.BusyPrice[0].StaHHMM;
	b3 = (DealCfg.BusyPrice[0].EndHHMM>>8)&0xFF;
	b4 = DealCfg.BusyPrice[0].EndHHMM;
	sprintf( (char*)buf, "高峰时间票价1:%u, %02X%02X-%02X%02X", 
	DealCfg.BusyPrice[0].UnitPrice, 
	b1,b2,b3,b4 );
	SysDebug_TxDataStr( buf );
	b1 = (DealCfg.BusyPrice[1].StaHHMM>>8)&0xFF;
	b2 = DealCfg.BusyPrice[1].StaHHMM;
	b3 = (DealCfg.BusyPrice[1].EndHHMM>>8)&0xFF;
	b4 = DealCfg.BusyPrice[1].EndHHMM;
	sprintf( (char*)buf, "高峰时间票价2:%u, %02X%02X-%02X%02X", 
	DealCfg.BusyPrice[1].UnitPrice, 
	b1,b2,b3,b4 );
	SysDebug_TxDataStr( buf );	
	b1 = (DealCfg.BusyPrice[2].StaHHMM>>8)&0xFF;
	b2 = DealCfg.BusyPrice[2].StaHHMM;
	b3 = (DealCfg.BusyPrice[2].EndHHMM>>8)&0xFF;
	b4 = DealCfg.BusyPrice[2].EndHHMM;
	sprintf( (char*)buf, "高峰时间票价3:%u, %02X%02X-%02X%02X", 
	DealCfg.BusyPrice[2].UnitPrice, 
	b1,b2,b3,b4 );
	SysDebug_TxDataStr( buf );	
	
	b1 = (DealCfg.BusyPrice3M[0].StaMMDD>>8)&0xFF;
	b2 = DealCfg.BusyPrice3M[0].StaMMDD;
	b3 = (DealCfg.BusyPrice3M[0].EndMMDD>>8)&0xFF;
	b4 = DealCfg.BusyPrice3M[0].EndMMDD;
	sprintf( (char*)buf, "高峰季节票价1:%u, %02X%02X-%02X%02X", 
	DealCfg.BusyPrice3M[0].UnitPrice, 
	b1,b2,b3,b4 );
	SysDebug_TxDataStr( buf );
	b1 = (DealCfg.BusyPrice3M[1].StaMMDD>>8)&0xFF;
	b2 = DealCfg.BusyPrice3M[1].StaMMDD;
	b3 = (DealCfg.BusyPrice3M[1].EndMMDD>>8)&0xFF;
	b4 = DealCfg.BusyPrice3M[1].EndMMDD;
	sprintf( (char*)buf, "高峰季节票价2:%u, %02X%02X-%02X%02X", 
	DealCfg.BusyPrice3M[1].UnitPrice, 
	b1,b2,b3,b4 );
	SysDebug_TxDataStr( buf );
	for( i = 0; i < DealCfg.CardTypeCout; i++ )
	{
		sprintf( (char*)buf, "%02u->卡类:%u,连刷:%u,钱折:%u,月折:%u,", i+1,
		DealCfg.DiscInfo[i].CardType,DealCfg.DiscInfo[i].TimeCout, DealCfg.DiscInfo[i].PurseDisc, DealCfg.DiscInfo[i].MonthDisc );
		SysDebug_TxDataStr( buf );
		if( ( DealCfg.DiscInfo[i].CardStat & 0x0008 ) == 0 )
		{ SysDebug_TxDataStr( (U08*)"禁高峰," ); }
		else
		{ SysDebug_TxDataStr( (U08*)"启高峰," ); }
		sprintf( (char*)buf, "次优先级:%d,月优先级:%d,钱优先级:%d,", ( ( DealCfg.DiscInfo[i].CardStat >> 11 ) & 0x0007 ), ( ( DealCfg.DiscInfo[i].CardStat >> 8 ) & 0x0007 ), ( ( DealCfg.DiscInfo[i].CardStat >> 0 ) & 0x0007 ) ); 
		SysDebug_TxDataStr( buf );
		if( ( DealCfg.DiscInfo[i].CardStat & 0x8000 ) != 0 )
		{ SysDebug_TxDataStr( (U08*)"启用," ); }
		else
		{ SysDebug_TxDataStr( (U08*)"禁用," ); }
		if( ( DealCfg.DiscInfo[i].CardStat & 0x4000 ) != 0 )
		{ SysDebug_TxDataStr( (U08*)"启黑," ); }
		else
		{ SysDebug_TxDataStr( (U08*)"禁黑," ); }
		sprintf( (char*)buf, "语音:%s,显示:%s", DealCfg.DiscInfo[i].AudioBuf, DealCfg.DiscInfo[i].DisBuf); 
		SysDebug_TxDataStr( buf );
	}
	
//============================>>用户文件 银行卡bin号
 	Err2:
	rcode = APP_Open_UseFile( DEF_USERID_UPBinInfo, sizeof( __UPBinInfo ) );
	if( rcode != 0 )
	{ goto Err3; }
	rcode = APP_Read_UseFile( DEF_USERID_UPBinInfo, (U08*)&UPBinInfo, sizeof( __UPBinInfo ) );
	if( rcode != 0 )
	{ goto Err3; }
	SysDebug_TxDataStr( (U08*)"=======>04 银行卡bin号" );
	sprintf( (char*)buf, "版本:%u", (UPBinInfo.Ver[0]<<24)|(UPBinInfo.Ver[1]<<16)|(UPBinInfo.Ver[2]<<8)|UPBinInfo.Ver[3] );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "数量:%u", UPBinInfo.Num );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "模式:%02X", UPBinInfo.Stat );
	SysDebug_TxDataStr( buf );
	for( i = 0; i < UPBinInfo.Num; i++ )
	{											
		sprintf( (char*)buf, "%02u-->%02X%02X%02X 卡类别:%02X 优惠开始日期:%02X%02X%02X 优惠结束日期:%02X%02X%02X 保留:%02X 折扣:%u", 
				i+1,
				UPBinInfo.Bin[i][0],UPBinInfo.Bin[i][1],UPBinInfo.Bin[i][2],
				UPBinInfo.Bin[i][3],
				UPBinInfo.Bin[i][4],UPBinInfo.Bin[i][5],UPBinInfo.Bin[i][6],
				UPBinInfo.Bin[i][7],UPBinInfo.Bin[i][8],UPBinInfo.Bin[i][9],
				UPBinInfo.Bin[i][10],
				UPBinInfo.Bin[i][11] );
		SysDebug_TxDataStr( buf );
	}

//============================>>用户文件 城市代码
 	Err3:
	rcode = APP_Open_UseFile( DEF_USERID_CityID, sizeof( __CityIDCfg ) );
	if( rcode != 0 )
	{ goto Err; }
	rcode = APP_Read_UseFile( DEF_USERID_CityID, (U08*)&CityIDCfg, sizeof( __CityIDCfg ) );
	if( rcode != 0 )
	{ goto Err; }
	SysDebug_TxDataStr( (U08*)"=======>05 城市代码" );
	sprintf( (char*)buf, "版本:%u", (CityIDCfg.Ver[0]<<24)|(CityIDCfg.Ver[1]<<16)|(CityIDCfg.Ver[2]<<8)|CityIDCfg.Ver[3] );
	SysDebug_TxDataStr( buf );
	sprintf( (char*)buf, "数量:%u", CityIDCfg.Num );
	SysDebug_TxDataStr( buf );
	for( i = 0; i < CityIDCfg.Num; i++ )
	{
		sprintf( (char*)buf, "%02u-->%02X%02X", i+1,CityIDCfg.OthCityID[i][0],CityIDCfg.OthCityID[i][1] );
		SysDebug_TxDataStr( buf );
	}	
	
	Err:
	SysDebug_TxDataStr( (U08*)"-------------------------END-----------------------" );
}
